package chat;

import java.io.Serializable;

import users.User;

/**
 * A UserMessage is a specific type of Message that a User sends
 * 
 * @author Lois Fozzard
 * 
 */
public class UserMessage extends Message implements Serializable
{
    private static final long serialVersionUID = 1L;
    private User user;
    private String wBrs;

    /**
     * Constructs the UserMessage
     * 
     * @param message
     *            the plain text String this Message is to contain (i.e. no html
     *            tags)
     * @param theUser
     *            the user who sent this message
     */
    public UserMessage(String message, User theUser)
    {
        super("<b>" + theUser.getName() + "</b>: " + message);
        user = theUser;
        wBrs = getPlainText().replace("\n", "<br/>");
    }
    
    public User getUser()
    {
        return user;
    }

    /**
     * returns the message in html tags to make it the User's color, in hex.
     * 
     * @return the message in html tags to make it the User's color
     */
    public String getHTML()
    {
        return "<font color='#"
                + Integer.toHexString(user.getColor().getRed() * 256 * 256 + user.getColor().getGreen()
                        * 256 + user.getColor().getBlue()) + "'>" + wBrs
                + "</font>";

    }

}
